package com.example.service;

import com.example.entity.Category;
import com.example.mapper.CategoryMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService {
    //注入Mapper
    @Resource
    private CategoryMapper categoryMapper;
    /**
     * 新增
     * */
    public void add(Category category) {
        categoryMapper.insert(category);
    }
    /**
     * 更新
     * */
    public void update(Category category) {
        categoryMapper.updateById(category);
    }
    /**
     * 删除
     * */
    public void deleteById(Integer id) {
        categoryMapper.deleteById(id);
    }
    /**
     * 查询所有
     * */
    public List<Category> selectAll(Category category) {
        return categoryMapper.selectAll(category);
    }
/**
 * 分页查询
 *  @param pageNum 页码
 *  @param pageSize 每页显示数量
 * @return  分页查询结果 返回Category对象
 * */
    public PageInfo<Category> selectPage(Category category, Integer pageNum, Integer pageSize) {
        //分页查询
        PageHelper.startPage(pageNum, pageSize);
        List<Category> list = categoryMapper.selectAll(category);
        return PageInfo.of(list);
    }


}
